package com.wuql.create.util;


/**
 * 数据表字段类型转Java类型工具类
 * @author : wuQingLiang
 * @date : 2024/3/14
 **/
public class ToJavaType {
    /**
     * mysql字段类型转Java类型
     * @param mysqlType mysql数据库字段类型名称
     * @return
     */
    public static String mysqlTypeToJavaType(String mysqlType) {
        switch (mysqlType) {
            case "int":
                return "Integer";
            case "bigint":
                return "Long";
            case "decimal":
            case "float":
            case "double":
                return "Double";
            case "varchar":
            case "char":
            case "text":
            case "tinyint":
            case "blob":
            case "longblob":
                return "String";
            case "date":
            case "time":
            case "timestamp":
            case "datetime":
                return "Date";
            case "bit":
                return "Boolean";
            default:
                return "Unknown Type";
        }
    }

    /**
     *  pgsql字段类型转Java类型
     * @param pgsqlType  pgsql数据库字段类型名称
     * @return
     */
    public static String pgsqlTypeToJavaType(String pgsqlType) {
        switch (pgsqlType) {
            case "int":
                return "Integer";
            case "bigint":
                return "Long";
            case "decimal":
            case "float":
            case "double":
            case "double precision":
                return "Double";
            case "varchar":
            case "char":
            case "text":
            case "tinyint":
            case "blob":
                return "String";
            case "date":
            case "time":
            case "timestamp":
            case "datetime":
            case "timestamp without time zone":
                return "Date";
            case "bit":
            case "boolean":
                return "Boolean";
            default:
                return "Unknown Type";
        }
    }
}
